home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 January / macformat46.iso / Shareware Plus / Developers / Library / AVF 1.1 Pack / AVF 1.1 pack ƒ folder / AVF 1.1 pack ƒ / ConnectixVdig ƒ / main.cp < prev   
Encoding:
Text File  |  1996-09-29  |  2.7 KB  |  107 lines

  1. // ---------------------------------------------------------------------------
  2. //        • AVF 1.1 - Asynchronous Video Framework
  3. //      • 
  4. //      • Philippe Lang, 1733 Treyvaux, SWITZERLAND
  5. //      • plang@com.mcnet.ch
  6. // ---------------------------------------------------------------------------
  7. //      This program demonstrates the uses of AVF with a BW QuickCam Camera
  8.  
  9. #include "VideoSession.h"
  10. #include "OffscreenWorld.h"
  11. #include "OffscreenGroup.h"
  12. #include "AsyncBuffer.h"
  13.  
  14. enum mainErr { NewCWindowErr };
  15.  
  16. main()
  17. {
  18.     // initialisation
  19.     InitGraf( &qd.thePort );        
  20.     InitFonts();                    
  21.     FlushEvents( everyEvent, 0 );
  22.     InitWindows();
  23.     InitMenus();
  24.     TEInit();
  25.     InitDialogs( nil );
  26.     InitCursor();
  27.     
  28.     MoreMasters();
  29.     MoreMasters();
  30.     MaxApplZone();
  31.     MaxApplZone();
  32.     
  33.     // program starts here
  34.     try
  35.     {
  36.         VideoSession        theSession( ConnectixVdig );
  37.         Rect                theOffscreenRect = {0, 0, 120, 160};
  38.         OffscreenWorld        theImage0( 16, theOffscreenRect, GetCTable(36) );
  39.         OffscreenWorld        theImage1( 16, theOffscreenRect, GetCTable(36) );
  40.         OffscreenWorld        theImage2( 16, theOffscreenRect, GetCTable(36) );
  41.         OffscreenGroup        theImageGroup;
  42.         theImageGroup.AddOffWorldPtr( &theImage0 );
  43.         theImageGroup.AddOffWorldPtr( &theImage1 );
  44.         theImageGroup.AddOffWorldPtr( &theImage2 );
  45.         AsyncBuffer            theBuffer( &theSession, &theImageGroup );
  46.                                                     
  47.         WindowPtr            theWin;
  48.         Rect                theWinPos = {100, 100, 220, 260};
  49.         theWin = NewCWindow( nil, &theWinPos, "\pVdig", true, movableDBoxProc, (WindowPtr)-1, 0, 0 );
  50.         if ( theWin == nil ) throw NewCWindowErr;
  51.         SetPort( theWin );
  52.         
  53.         VDGrabOneFrameAsync( theSession.VdigComponent(), 1 );
  54.         do
  55.         {    
  56.             while ( !VDDone( theSession.VdigComponent(), 0 ) ) {};
  57.             VDGrabOneFrameAsync( theSession.VdigComponent(), 2 );
  58.             CopyBits( (BitMap*)*theImage2.PixMapH(), &theWin->portBits, &theOffscreenRect, &theOffscreenRect, srcCopy, nil );
  59.             
  60.             while ( !VDDone( theSession.VdigComponent(), 1 ) ) {};
  61.             VDGrabOneFrameAsync( theSession.VdigComponent(), 0 );
  62.             CopyBits( (BitMap*)*theImage0.PixMapH(), &theWin->portBits, &theOffscreenRect, &theOffscreenRect, srcCopy, nil );
  63.             
  64.             while ( !VDDone( theSession.VdigComponent(), 2 ) ) {};
  65.             VDGrabOneFrameAsync( theSession.VdigComponent(), 1 );
  66.             CopyBits( (BitMap*)*theImage1.PixMapH(), &theWin->portBits, &theOffscreenRect, &theOffscreenRect, srcCopy, nil );
  67.         }
  68.         while ( !Button() );
  69.         
  70.         DisposeWindow( theWin );
  71.     }
  72.     
  73.     // exception handlers
  74.     catch ( VideoErr    theErr )
  75.     {
  76.         SysBeep(0);
  77.         ExitToShell();
  78.     }
  79.     
  80.     catch ( OffscreenErr theErr )
  81.     {
  82.         SysBeep(0);
  83.         ExitToShell();
  84.     }
  85.     
  86.     catch ( AsyncBufferErr theErr )
  87.     {
  88.         SysBeep(0);
  89.         ExitToShell();
  90.     }
  91.     
  92.     catch ( mainErr theErr )
  93.     {
  94.         SysBeep(0);
  95.         ExitToShell();
  96.     }
  97.     
  98.     catch ( OffscreenGroupErr theErr )
  99.     {
  100.         SysBeep(0);
  101.         ExitToShell();
  102.     }
  103.     
  104.     // program is finished
  105.     return (1);
  106. };
  107.